package com.bignerdranch.android.ecar.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bignerdranch.android.ecar.R;

import org.json.JSONArray;
import org.json.JSONException;

/**
 * Created by Administrator on 2016/7/22.
 */
public class ProvinceAdapter extends BaseAdapter {

    private Context mContext ;
    private LayoutInflater mInflater;
    private String [] location;

    public ProvinceAdapter(Context context, String [] location) {
        mContext = context;
        this.location = location;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return location.length;
    }

    @Override
    public Object getItem(int position) {

            return location[position];

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView = mInflater.inflate(R.layout.province_item,null);
        }
        ViewHold hold = new ViewHold();
        if (convertView.getTag()==null){
            hold.province = (TextView) convertView.findViewById(R.id.province_item);

            convertView.setTag(hold);
        }else {
            hold = (ViewHold) convertView.getTag();
        }


            hold.province.setText(location[position]);


        return convertView;
    }
    private static class ViewHold{
        private TextView province;
    }
}
